package com.antgroup.seckill.business.common.rocketmq;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * @author wangxy
 * @date 2024/8/11 17:07
 */
@Service
@Slf4j
public class RocketMqSender {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;


    /**
     * 发送消息
     *
     * @param topic
     * @param message
     */
    public void sendMessage(String topic,String message) {
        log.info("发送消息：" + message);
        rocketMQTemplate.convertAndSend(topic,message);

        /*// 创建消息
        Message<String> message = MessageBuilder.withPayload(payload)
                .setHeader(RocketMQHeaders.TAGS, tag)
                .build();

        rocketMQTemplate.convertAndSend(topic,message);*/
    }
}
